<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <ul>
            <!-- 若不写key，则vue会自动用index作为key的值 -->
            <!-- <li v-for="(p, index) in peoples" :key="index"> -->
            <!-- 尽量用元素的唯一标识作为 key 的值 -->
            <li v-for="(p, index) in peoples" :key="p.id">
                name:{{p.name}}, age:{{p.age}} <input type="text">
            </li>
        </ul>
        <button @click="add">添加</button>
    </div>
    <script>
        Vue.config.productionTip = false;
        let vm = new Vue({
            el: '#root',
            data: {
                peoples:[
                    {id:001, name:'张三', age:17},
                    {id:002, name:'李四', age:19},
                    {id:003, name:'王五', age:21},
                ],
            },
            methods: {
                add(){
                    // 在第一个元素前面插入
                    this.peoples.unshift({id:004,name:'老王',age:70});
                }
            },
        });
    </script>
</body>
</html>